#include<bits/stdc++.h>
using namespace std;

struct node {
    int val, cnt;
};

int f[1005];

signed main() {
    int n;
    cin >> n;
    while(n--) {
        int k, x;
        cin >> k;
        while(k--) {
            cin >> x;
            f[x]++;
        }
    }

    vector<node> a;
    for(int i = 1; i <= 1000; i++) {
        a.push_back({i, f[i]});
    }

    sort(a.begin(), a.end(), [](node x, node y) {
        if(x.cnt != y.cnt)
            return x.cnt > y.cnt;
        else
            return x.val > y.val;
    });

    cout << a[0].val << " " << a[0].cnt;

    return 0;
}

